import os
from datetime import timedelta

class Config:
    """基础配置类"""
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'your-secret-key-here'
    
    # 数据库配置
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
        'mysql+pymysql://root:mahui123456.@localhost:3306/love?charset=utf8mb4'
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    
    # JWT配置
    JWT_SECRET_KEY = os.environ.get('JWT_SECRET_KEY') or 'jwt-secret-string'
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=24)
    JWT_REFRESH_TOKEN_EXPIRES = timedelta(days=30)
    
    # CORS配置
    CORS_ORIGINS = ["http://localhost:3000", "http://127.0.0.1:3000"]
    
    # 微信小程序配置
    WECHAT_APPID = 'wxb864303341ad205b'
    WECHAT_SECRET = 'b51030345059c9f6fe69559c3cb3810e'
    
    # 短信服务配置（阿里云SMS）
    SMS_ACCESS_KEY_ID = os.environ.get('SMS_ACCESS_KEY_ID') or 'your-access-key-id'
    SMS_ACCESS_KEY_SECRET = os.environ.get('SMS_ACCESS_KEY_SECRET') or 'your-access-key-secret'
    SMS_SIGN_NAME = os.environ.get('SMS_SIGN_NAME') or '相亲交友平台'
    SMS_TEMPLATE_CODE = os.environ.get('SMS_TEMPLATE_CODE') or 'SMS_123456789'
    
    # 文件上传配置
    UPLOAD_FOLDER = os.environ.get('UPLOAD_FOLDER') or 'D:/uploads/falling-love'
    MAX_CONTENT_LENGTH = 16 * 1024 * 1024  # 16MB max file size
    ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'webp', 'pdf', 'doc', 'docx', 'txt'}
    
    # 文件访问URL前缀
    FILE_URL_PREFIX = os.environ.get('FILE_URL_PREFIX') or 'http://127.0.0.1:5000/uploads'
    
    # Redis配置
    REDIS_URL = os.environ.get('REDIS_URL') or 'redis://localhost:6379/0'
    
    # 缓存配置
    CACHE_TYPE = 'redis'
    CACHE_REDIS_URL = REDIS_URL
    CACHE_DEFAULT_TIMEOUT = 300  # 5分钟默认缓存时间


class DevelopmentConfig(Config):
    """开发环境配置"""
    DEBUG = True


class ProductionConfig(Config):
    """生产环境配置"""
    DEBUG = False


config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
} 